@include('Home.head')
<style>
    .am-header-default{
        background-color: #CC3436;
    }
    .am-navbar-nav a .am-navbar-label{
        font-size: 14px;
        margin-top: 6px;
    }
    .am-navbar{
        height: 60px;
    }
    .panel-wrapper {
        position: relative;
    }

    .panel-wrapper .del {
        position: absolute;
        right: 5px;
        bottom: 20px;
    }

    .panel-wrapper .edit {
        position: absolute;
        right: 40px;
        bottom: 20px;
    }
</style>
<body>
<div class="container" id="app">
    @include('Home.member.header')
    <div class="am-cf cart-panel ">
        <div class="withdrawals-panel">
            <div class="partners-title-panel panel-wrapper" v-for="val,index in addresslist">
                <div class="partners-title-panel-title" style="height: 80px;padding-left: 10px;" v-on:click="jump(val.id)">
                    @{{ val.name }} &nbsp;@{{ val.phone }} <a v-show="val.default" style="color: red">默认地址</a><br>
                    <a style="width:100%;height:49px;font-size: 12px;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">@{{
                        val.province }}@{{ val.city }}@{{ val.district }}@{{ val.address }}</a>
                    <span class="am-fr am-icon-trash-o del" v-on:click="del(val.id,index)"></span><span
                            class="am-fr am-icon-pencil-square-o edit" v-on:click="edit(val.id)"></span>
                </div>
            </div>
        </div>
        <p class="am-text-center" onclick="window.location.href='/home/member/address'">

            <button type="button" class="am-btn am-btn-danger am-radius am-btn-block" style="border-radius: 50px;border: none;">添加收货地址</button>

        </p>
    </div>
    @include('Home.foot')
</div>
</body>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            title: '收货地址',
            address: {
                'id': '',
                'uid': '',
                'phone': '',
                'zip_code': '',
                'landline': '',
                'name': '',
                'province': '',
                'city': '',
                'district': '',
                'address': '',
                'default': '',
            },
            addresslist: [],
        },
        methods: {
            //初始化 系统管理员列表
            initialize: function () {
                $.post("/home/member/addaddress", {'_token': '{{csrf_token()}}', class: 'select'}, function (res) {
                    if (res.code) {
                        app.addresslist = res.data
                    } else {
                        layer.msg(res.data,{icon:7});
                    }
                });
            },
            add: function () {
                $.post("/home/member/addaddress", {
                    '_token': '{{csrf_token()}}',
                    class: 'add',
                    address: app.address
                }, function (res) {
                    if (res.code) {
                        layer.msg(res.data,{icon:7});
                    } else {
                        layer.msg(res.data,{icon:7});
                    }
                });
            },
            del: function (id, index) {
                if (app.addresslist[index].default == 1) {
                    layer.msg('默认地址不能删除!');
                    return false;
                }
                $.post("/home/member/addaddress", {
                    '_token': '{{csrf_token()}}',
                    class: 'delete',
                    id: id
                }, function (res) {
                    if (res.code) {
                        app.addresslist.splice(index, 1)
                    } else {
                        layer.msg(res.data,{icon:7});
                    }
                });
            },
            edit: function (id) {
                window.location.href = "/home/member/address?id=" + id;
            },
            jump:function (id) {
                console.log(id)
                var order_id=this.obtain('order_id');
                console.log(order_id)
                if (order_id != undefined && order_id != 0 && order_id != null){
                    window.location.href="/home/orderpage?id=" + order_id +"&address_id="+id;
                }
            },
            //获取url id
            obtain:function (val) {
                var query = window.location.search.substring(1);
                var vars = query.split("&");
                for (var i=0;i<vars.length;i++) {
                    var pair = vars[i].split("=");
                    if(pair[0] == val){
                        return pair[1];
                    }
                }
            }
        },
        //自动执行
        mounted: function () {
            this.initialize();//分公司
        },
    });
</script>
</html>
